package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnMedicine;
import com.nmsl.sn.service.ISnMedicineService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 药品信息维护Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/sn/medicineinfo")
public class SnMedicineController extends BaseController
{
    @Autowired
    private ISnMedicineService snMedicineService;

    /**
     * 查询药品信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnMedicine snMedicine)
    {
        startPage();
        List<SnMedicine> list = snMedicineService.selectSnMedicineList(snMedicine);
        return getDataTable(list);
    }

    /**
     * 导出药品信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:export')")
    @Log(title = "药品信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnMedicine snMedicine)
    {
        List<SnMedicine> list = snMedicineService.selectSnMedicineList(snMedicine);
        ExcelUtil<SnMedicine> util = new ExcelUtil<SnMedicine>(SnMedicine.class);
        util.exportExcel(response, list, "药品信息维护数据");
    }

    /**
     * 获取药品信息维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:query')")
    @GetMapping(value = "/{medicineId}")
    public AjaxResult getInfo(@PathVariable("medicineId") Long medicineId)
    {
        return success(snMedicineService.selectSnMedicineByMedicineId(medicineId));
    }

    /**
     * 新增药品信息维护
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:add')")
    @Log(title = "药品信息维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnMedicine snMedicine)
    {
        return toAjax(snMedicineService.insertSnMedicine(snMedicine));
    }

    /**
     * 修改药品信息维护
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:edit')")
    @Log(title = "药品信息维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnMedicine snMedicine)
    {
        return toAjax(snMedicineService.updateSnMedicine(snMedicine));
    }

    /**
     * 删除药品信息维护
     */
    @PreAuthorize("@ss.hasPermi('sn:medicineinfo:remove')")
    @Log(title = "药品信息维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medicineIds}")
    public AjaxResult remove(@PathVariable Long[] medicineIds)
    {
        return toAjax(snMedicineService.deleteSnMedicineByMedicineIds(medicineIds));
    }
}
